package za.ac.cput.arrowgame.service.trunarrow;

import org.springframework.stereotype.Service;
import za.ac.cput.arrowgame.model.Arrow;
import za.ac.cput.arrowgame.model.Direction;
import za.ac.cput.arrowgame.model.Grid;

@Service("trunArrowService")
public class TrunArrowServiceImpl implements TrunArrowService {

    public Grid turnClockwise(Grid gridModel) {
        final Arrow arrow = gridModel.getArrow();
        Direction direction = arrow.getDirection();
        switch (direction) {
            case NORTH:
                arrow.setDirection(Direction.NORTHEAST);
                break;
            case NORTHEAST:
                arrow.setDirection(Direction.EAST);
                break;
            case EAST:
                arrow.setDirection(Direction.SOUTHEAST);
                break;
            case SOUTHEAST:
                arrow.setDirection(Direction.SOUTH);
                break;
            case SOUTH:
                arrow.setDirection(Direction.SOUTHWEST);
                break;
            case SOUTHWEST:
                arrow.setDirection(Direction.WEST);
                break;
            case WEST:
                arrow.setDirection(Direction.NORTHWEST);
                break;
            case NORTHWEST:
                arrow.setDirection(Direction.NORTH);
                break;
        }
        gridModel.setArrow(arrow);
        return gridModel;
    }

    public Grid turnAnitClockwise(Grid gridModel) {
        final Arrow arrow = gridModel.getArrow();
        Direction direction = arrow.getDirection();
        switch (direction) {
            case NORTH:
                arrow.setDirection(Direction.NORTHWEST);
                break;
            case NORTHWEST:
                arrow.setDirection(Direction.WEST);
                break;
            case WEST:
                arrow.setDirection(Direction.SOUTHWEST);
                break;
            case SOUTHWEST:
                arrow.setDirection(Direction.SOUTH);
                break;
            case SOUTH:
                arrow.setDirection(Direction.SOUTHEAST);
                break;
            case SOUTHEAST:
                arrow.setDirection(Direction.EAST);
                break;
            case EAST:
                arrow.setDirection(Direction.NORTHEAST);
                break;
            case NORTHEAST:
                arrow.setDirection(Direction.NORTH);
                break;
        }
        gridModel.setArrow(arrow);
        return gridModel;
    }
}
